package com.zjitc.controller;

import com.zjitc.model.AdminUser;
import com.zjitc.model.User;
import com.zjitc.service.AdminService;
import java.util.List;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.MvcNamespaceHandler;
import org.springframework.web.servlet.view.InternalResourceView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpSession;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/19 15:46
 * @description:
 */
@Controller
public class AdminUserCon {
    @Autowired
    AdminService adminService;
    private ModelAndView mv =new ModelAndView();
    @RequestMapping("/loginn")
    public ModelAndView loginn(@RequestParam("username")String username,
                              @RequestParam("password")String password,
                              HttpSession session) {
      AdminUser adminUser = adminService.findAdmin(username);
      if(adminUser.getPassword().equals(password)){
          session.setAttribute("adminUser",adminUser);
          mv.setView(new InternalResourceView("/admin/home.jsp"));
      }else{
          mv.addObject("msg","cuo wu");
          mv.setView(new InternalResourceView("/admin/login.jsp"));
      }
      return mv;
    }
    @RequestMapping("/deleteById")
    public ModelAndView deleteById(@RequestParam("username")String username){
        adminService.deleteById(username);
        mv.setView(new InternalResourceView("/admin/user/list.jsp"));
        return mv;
    }




}
